package com.yyj.controller;

import com.yyj.dto.CyRoomDto;
import com.yyj.entity.CyRoom;
import com.yyj.entity.PageResult;
import com.yyj.service.CyRoomService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  
 *
 * @author 汪彬彬
 * @since 2025-03-29 19:41:13
 */
@RestController
@RequestMapping("/api/cyRoom")
@Tag(name = " 控制器")
public class CyRoomController {

    @Autowired
    private CyRoomService cyRoomService;

    /**
     * 分页查询
     *
     * @param params
     * @return
     */
    @Operation(method = "分页查询",description = "分页查询")
    @ApiResponses({@ApiResponse(responseCode = "200", description = "查询成功")})
    @PostMapping("/findPage")
    public ResponseEntity<PageResult<CyRoom>> findPage(@RequestBody CyRoomDto params) {
        PageResult<CyRoom> result = cyRoomService.findPage(params);
        return ResponseEntity.ok(result);
    }
    /**
     * 列表查询
     *
     * @param params
     * @return
     */
    @Operation(method = "分页查询",description = "分页查询")
    @ApiResponses({@ApiResponse(responseCode = "200", description = "查询成功")})
    @PostMapping("/findList")
    public ResponseEntity<List<CyRoom>> findList(@RequestBody CyRoom params) {
        List<CyRoom> result = cyRoomService.findList(params);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @Operation(method = "分页查询",description = "分页查询")
    @ApiResponses({@ApiResponse(responseCode = "200", description = "查询成功")})
    @GetMapping("/{id}")
    public ResponseEntity<CyRoom> findById(@PathVariable("id") Long id) {
        CyRoom cyRoom = cyRoomService.findById(id);
        return ResponseEntity.ok(cyRoom);
    }

    /**
     * 新增
     *
     * @param cyRoom
     * @return
     */
    @Operation(method = "分页查询",description = "分页查询")
    @ApiResponses({@ApiResponse(responseCode = "200", description = "查询成功")})
    @PostMapping
    public ResponseEntity<Integer> insert( @Validated  @RequestBody CyRoom cyRoom) {
        int result = cyRoomService.insert(cyRoom);
        return ResponseEntity.ok(result);
    }

    /**
     * 修改
     *
     * @param cyRoom
     * @return
     */
    @Operation(method = "分页查询",description = "分页查询")
    @ApiResponses({@ApiResponse(responseCode = "200", description = "查询成功")})
    @PutMapping
    public ResponseEntity<Integer> update( @Validated  @RequestBody CyRoom cyRoom) {
        int result = cyRoomService.update(cyRoom);
        return ResponseEntity.ok(result);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Operation(method = "分页查询",description = "分页查询")
    @DeleteMapping("/{id}")
    public ResponseEntity<Integer> delete(@PathVariable("id") Long id) {
        int result = cyRoomService.delete(id);
        return ResponseEntity.ok(result);
    }

}
